//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {}, 
    avatarUrl: "/images/default_avatar.jpg", 
    hasUserInfo: false, 
    canIUseGetUserProfile: false, 
  },
  toSelect() { 
    console.log(typeof(this.data.userInfo.avatarUrl)) 
    var avatarUrl = this.data.userInfo.avatarUrl 
    var hasUserInfo = this.data.hasUserInfo 
    wx.navigateTo({ 
      url: '../select/select?avatarUrl='+avatarUrl+"&hasUserInfo="+hasUserInfo 
    }) 
  }, 
  onLoad: function() { 
    if (wx.getUserProfile) { 
      console.log("Can use")
      this.setData({ 
        canIUseGetUserProfile: true 
      }) 
    } 
    else{
      console.log("Can not")
    }
  }, 
  getUserProfile(e) { 
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认 
    // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗 
    var that = this; 
    wx.getUserProfile({ 
      desc: '请授权允许使用头像', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写 
      success: (res) => { 
        console.log(res.userInfo) 
        this.setData({ 
          userInfo: res.userInfo, 
          hasUserInfo: true, 
        }) 
        that.toSelect() 
      }, 
      // 无论用户是否授权都跳转到下一页 
      fail:(res)=>{ 
        console.log("Before navigate to") 
        console.log(app.globalData.userInfo) 
        console.log(app.globalData.hasUserInfo) 
        that.toSelect() 
      } 
    }) 
  }, 
  bindGetUserInfo (e) { 
    console.log(e.detail.userInfo) 
  }
})